<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>属性侦听器</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>

<body>
    <div id="Application">
        <!-- 定义一个输入框，监听用户输入的内容 -->
        <input v-model="searchText" />
    </div>
    <script>
        const App = {
            data() {
                return {
                    searchText: ""
                }
            },

            // 监控变量的使用
            watch: {
                searchText(newValue, oldValue) {
                    console.log(newValue, oldValue)
                    if (newValue.length > 10) {
                        alert("文本太长了")
                    }
                }
            }
        }
        Vue.createApp(App).mount("#Application") 
    </script>
</body>

</html>